import java.awt.*;

import javax.swing.*;

public class ItemsLayer extends JPanel {
	Cursor cursor;
	Item[] items;
	String[] imageFile = { "hp_up.png", "armor_up.png" };
	Image[] image = new Image[imageFile.length];

	public ItemsLayer(Cursor cursor, Item[] items) {
		this.cursor = cursor;
		this.items = items;
		this.setFocusable(false);

		// Initialize images from their file names
		MediaTracker media = new MediaTracker(this);
		for (int i = 0; i < imageFile.length; i++) {
			image[i] = Toolkit.getDefaultToolkit().getImage(
					"graphics\\" + imageFile[i]);
			media.addImage(image[i], 0);
			try {
				media.waitForID(0);
			} catch (Exception e) {
			}

		}
	}

	public void paint(Graphics g) {
		this.setLocation(0, 0);
		int w = 850, h = 550;
		this.setSize(w, h);

		int posx, posy;
		posx = -8 + cursor.getx();
		posy = -5 + cursor.gety();

		// Populate the map with item images
		for (int i = 0; i < items.length; i++) {
			if (items[i] == null) {

			} else {
				int x = (items[i].getX() - posx);
				int y = (items[i].getY() - posy);
				if ((x < 0) || (x > 16) || (y < 0) || (y > 16)) {
					// Outside of areaView bounds
				} else {
					// Draw building image

					g.drawImage(image[items[i].getType() - 40], x * 50, y * 50,
							this);
				}
			}
		}
	}
}
